﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/*
 Linq Lesson
 */
namespace csharp_linq_415
{
    class Program
    {
        static void Main(string[] args)
        {
            // List of names
            List<string> nameList = new List<string>() { "Smith", "Michelle", "Ellie", "Liel" };

            // Gets all names that contain "ll"
            //var res = nameList.Where(n => n.Contains("mi")).ToList(); // case sesitive
            //var res = nameList.Where(n => n.ToLower().Contains("ll")).ToList(); // normalized the elements
            //var res = nameList.Where(n => n.Length > 5).ToList(); // items with 5 chars
            //var res = nameList.OrderBy(n => n.Length).ToList(); // sort by names length
            //var res = nameList.OrderBy(n => n.Length).Select(n => n.ToUpper()).ToList(); // sort by names length & make all caps
            var res = nameList.Where(n => n.Contains("ll")).OrderBy(n => n.Length).Select(n => n.ToUpper()).ToList(); // Get names with "ll", order by length, make all caps

            
            // Output the results with a loop
            foreach (var item in res)
            {
                //Console.WriteLine("names: {0}", item);
            }
           
            /// create the todos, then add a list
            Todo t1 = new Todo() { Task = "attend Demo Day", IsCompleted = false, AssignedToPerson = "All students", DateCreated = DateTime.Now.AddDays(-7) };
            Todo t2 = new Todo() { Task = "do your homework", IsCompleted = true, AssignedToPerson = "Keigo", DateCreated = DateTime.Now.AddDays(-1) };
            Todo t3 = new Todo() { Task = "Beat the Spurs", IsCompleted = true, AssignedToPerson = "Josh", DateCreated = DateTime.Now };
            List<Todo> tList = new List<Todo>();
            tList.Add(t1);
            tList.Add(t2);
            tList.Add(t3);

            // fetch todos that now complete
            //List<Todo> tRes = tList.
            //var tRes = tList.Where(t => t.IsCompleted == true).ToList(); // get items that are completed

            var tRes = tList.Where(t => t.Task.Contains("Demo")).ToList(); // get items that contain the word DEMO



            // Output the results with a loop
            foreach (var item in tRes)
            {
                Console.WriteLine("Todos: {0}", item.Task);
            }

            Console.ReadLine();
            /// end main
        }


    }

    // Todo Class
    public class Todo
    {
        public string Task { get; set; }
        public bool IsCompleted { get; set; }
        public DateTime DateCreated { get; set; }
        public string AssignedToPerson { get; set; }
    }



}
